package ink.wbc.drools;

import ink.wbc.drools.entity.User;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

/**
 * @author wbc
 * @date 2021/9/15
 * @desc
 */
public class DroolsMain {

    public static void main(String[] args) {
        KieServices kieServices = KieServices.Factory.get();
        //获取KieContainer对象
        KieContainer kieClasspathContainer = kieServices.getKieClasspathContainer();
        //从Kie容器对象中获取会话对象，用于和规则引擎交互
        KieSession kieSession = kieClasspathContainer.newKieSession();


        User user = new User();
        user.setMoney(200);

        //将数据提供给规则引擎
        kieSession.insert(user);
        //激活规则引擎，由Drools框架自动进行规则匹配，如果规则匹配成功则执行规则
        kieSession.fireAllRules();
        kieSession.dispose();
        System.out.println("是否允许抽奖：" + user.getAllowLotteryFlag().equals(1));
    }
}
